<?php defined('SYSPATH') or die('No direct script access.');

/**
 * Menu User
 * ID_user : int 10 = kode user
 * username : varchar 32 
 * password : bigint 20 = password pake hashing md5
 * ID_role : int 10 
 *
 * bahan suatu menu didefinisikan di tabel membutuhkan
 *
 */


class User_Model extends Model {

	//ambil user dengan id tertentu
	public function get_user($id_user)
	{
		return $this->db->from('user')->where('ID_user',$id_user)->get();
	}
	
	//Masukin user dengan  informasi tentang user tersebut ditaro di array associative data
	public function insert_user($data)
	{		
		$query = $this->db->insert('user', $data);
		return $query->insert_id();		
	}
 
	//ubah atau tambah data pada user dengan id tertentu
	public function update_user($user_id, $data)
	{ 
		$this->db->where('id', $user_id);		
		$this->db->update('user', $data);		
	}
	
	
	//ngecek apakah ada di database user si user dan password dengan enkirpsi md5
	public function check_user_and_password($user,$pwd) 
	{
		$md5pwd = md5($pwd);
		$query = $this->db->select()->where(array('username' => $user,'password'=>$md5pwd))->from('user')->get();
		return $query;
	}
	
	//dapetin semua pengguna yang terdaftar, sudah termasuk data join dari tabel lokasi
	public function get_all_user() 
	{
		$this->db->from('user');
		return $this->db->select(
			'user.ID_user AS user_ID_user',
			'user.username AS user_username',
			'role.nama AS role_nama'
		)->orderby('ID_user')->join('role','user.ID_role','role.ID_role')->get();
	}
	
}